package week_01;

public class MoveZeroes_283 {
    public void moveZeroes(int[] nums) {
        // 主题思路：保留非零值
        int n = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != 0) {
                nums[n] = nums[i];
                n++;
            }
        }
        while (n < nums.length) {
            nums[n] = 0;
            n++;
        }
    }

    public void moveZeroes1(int[] nums) {
        int x = 0;
        int y = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 0) {
                y++;
            } else {
                if (y > 0) {
                    nums[x] = nums[i];
                    nums[i] = 0;
                }
            }
            x = i - y + 1;
        }

    }
}
